package com.tlgen.service;

import com.tlgen.mapper.EnrollMapper;
import com.tlgen.model.Enroll;
import com.tlgen.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: tlgen
 * @Discription:
 */
@Service
public class EnrollService {

    @Autowired
    EnrollMapper enrollMapper;

    public Integer addEnrolls(List<Enroll> list) {
        return enrollMapper.addEnrolls(list);
    }

    public RespPageBean getEnrollByPage(Integer page, Integer size, Enroll enroll) {
        if (page != null && size != null) {
            page = (page-1) * size;
        }
        List<Enroll> data = enrollMapper.getEnrollByPage(page, size, enroll);
        Long total = enrollMapper.getTotal(enroll);
        RespPageBean bean = new RespPageBean();
        bean.setData(data);
        bean.setTotal(total);
        return bean;
    }

    public Integer addEnroll(Enroll Enroll) {
        Enroll.setCreateDate(new Date());
        Enroll.setUpdateDate(new Date());
        Enroll.setEnabled(true);
        return enrollMapper.insertSelective(Enroll);
    }

    public Integer deleteEnrollByEid(Integer id) {
        return enrollMapper.deleteByPrimaryKey(id);
    }

    public Integer updateEnroll(Enroll Enroll) {
        Enroll.setUpdateDate(new Date());
        return enrollMapper.updateByPrimaryKeySelective(Enroll);
    }
}
